home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: netcom.com!bnelson
- From: bnelson@netcom.com (Bob Nelson)
- Subject: Re: How to use assert( )
- Message-ID: <bnelsonDpn06z.CFq@netcom.com>
- Organization: a computer running Linux
- X-Newsreader: TIN [version 1.2 PL2]
- References: <4kc3k7$dur@orion.cybercom.net> <smryanDpKxLz.39v@netcom.com>
- Date: Wed, 10 Apr 1996 08:13:46 GMT
- Sender: bnelson@netcom17.netcom.com
-
- On Tue, 9 Apr 1996 05:22:47 GMT, @#$%!?! wrote:
- >> #include <assert.h>
- >> assert(some_expression_which_must_be_true);
- >> as in
- >> assert(f=fopen("name","r"));
-
- This particular usage example has an obvious drawback if 'f' is used
- later in the program (as is likely) and NDEBUG is defined.
-
- >> If the expression is false, the program is aborted. On a Unix system, it
- >> will print the file name, line number, and the failed expression to stderr.
-
- Why limit the explanation of its behavior in terms of one particular
- platform in a newsgroup devoted to Standard C? In the spirit of system
- independence, please permit this abridged quote from the ISO document
- (7.2.1.1):
-
- "When it is executed, if _expression_ is false [...] the assert macro
- writes information about the particular call that failed [...] on the
- standard error file in an implementation-defined format."
-
- A footnote (97) adds that the message may be:
- "Assertion failed: _expression_, file _xyz_, line nnn"
-
- Aside to Steve Summit -- might a brief foray into the proper use of
- the wondrous assert macro be worthy of inclusion in the FAQ?
-
- --
- =============================================================================
- Bob Nelson: Dallas, Texas, U.S.A. - bnelson@netcom.com
- Linux for fun, M$ for $$$...and the NFL for what really counts!
- =============================================================================
-
-